package cn.edu.zzu.demo03ThreadSecurity;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * JUC下的线程安全的list
 */
public class TestJucThread {

    public static void main(String[] args) throws InterruptedException {
        CopyOnWriteArrayList<String> strings = new CopyOnWriteArrayList<>();

        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                strings.add(Thread.currentThread().getName());
            }).start();
        }

        Thread.sleep(3000);

        System.out.println(strings.size());
    }
}
